<?php
/**
 * created by zzy
 * date: 2018/1/26 14:07
 */


namespace App\Api\Service\Company\Controllers;

use App\Eloquent\Ygt\DepartmentUser;
use App\Eloquent\Ygt\Order;
use Framework\BaseClass\Api\Controller;
use App\Eloquent\Ygt\Logistics;
use App\Eloquent\Ygt\LogisticsNotes;
use App\Engine\Func;

class LogisticsController extends Controller
{
    public function index(){}
    public function lists()
    {
        $userId             = Func::getHeaderValueByName('userid');
        $userInfo           = DepartmentUser::getCurrentInfo($userId);
        if( !$userInfo ){
            xThrow( ERR_PARAMETER );
        }
        $companyId          = $userInfo->company_id;
        $where              = ['company_id'=>$companyId];
        $collection         = Logistics::getList($where);
        $result             = $collection->toArray();
        return $result;
    }
    public function detail()
    {
        $logisticsId        = request('id',0);
        $where              = ['id'=>$logisticsId];
        $logistics          = Logistics::getInfo($where)->toArray();
        return $logistics;
    }
    public function notesList()
    {
        $logisticsId        = request('id',0);
        $where              = ['logistics_id'=>$logisticsId];
        $collection         = LogisticsNotes::getList($where);
        $result             = $collection->toArray();
        return $result;
    }
    public function notesDetail()
    {
        $notesId            = request('id',0);
        $where              = ['id'=>$notesId];
        $notes              = LogisticsNotes::getInfo($where)->toArray();
        $orderId            = $notes['order_id'];
        $order              = Order::where('id',$orderId)->first();
        $result             = ['notes'=>$notes,'order'=>$order];
        return $result;
    }
}